#加载quantmod包
if(!require(quantmod)){ install.packages("quantmod") }
if(!require(shiny)){ install.packages("shiny") }

library(shiny)
library(quantmod)
library(markdown)
library(ggplot2)

function(input, output, session) {
  #Symbols
  output$dateText  <- renderText({
    paste("input$date is", as.character(input$date))
  })
  output$dateRangeText  <- renderText({
    paste("input$dateRange is", 
          paste(as.character(input$dateRange), collapse = " to ")
    )
  })
  output$symbol <- DT::renderDataTable({
    DT::datatable(iris, options = list(lengthMenu = c(5, 30, 50), pageLength = input$tbs))
  })

  #Scans
  datasetInput <- reactive({
    switch(input$dataset,
           "rock" = rock,
           "pressure" = pressure,
           "cars" = cars)
  })
  output$scan <- renderTable({
    head(datasetInput(), n = input$obs)
  })
  output$caption <- renderText({
    input$caption
  })
  output$summary <- renderPrint({
    dataset <- datasetInput()
    summary(dataset)
  })
  
  
  dataInput <- reactive({   
    data1 <- getSymbols(input$stock,src="yahoo",
             from=input$dtRange[1],to=input$dtRange[2],auto.assign=FALSE)
    return (list(data1))
  })
  #Views
  output$view <- renderPlot({
    chartSeries(dataInput()[[1]],name=input$stock,up.col='red',dn.col='green',TA="addVo();addMACD(); addSMA(n=5); addLines(h=c(135,159)) ")
  })
  
  #Us for me
  output$us <- renderPrint({
    summary(cars)
  })
  
}
